from django import forms
from django.contrib.auth.models import User
from users.models import UserProfile


class UserForm(forms.ModelForm):
    class Meta:
        model = User
        fields = ('username','password','first_name', 'last_name', 'email')
    def __init__(self, *args, **kwargs):
        super(UserForm, self).__init__(*args, **kwargs)
    def save(self, commit=True):
        user = super(UserForm, self).save(commit=False)
        user.set_password(self.cleaned_data["password"])
        if commit:
            user.save()
        return user


class ProfileForm(forms.ModelForm):
    class Meta:
        model = UserProfile
        fields = ('phone', 'qqnum', 'weixin','avatar')
        # fields = '__all__'